//
//  WFFarmCropCell.m
//  WisdomFarm
//
//  Created by sky on 2017/11/13.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFFarmCropCell.h"

@implementation WFFarmCropCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setup];
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setup];
    }
    return self;
}

- (void)setup {
//    _editButton = [[UIButton alloc] init];
//    [self.contentView addSubview:_editButton];
    _deleteButton = [[UIButton alloc] init];
    [self.contentView addSubview:_deleteButton];
    _nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_nameLabel];
    _phaseLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_phaseLabel];

//    [_editButton mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.deleteButton.mas_left).offset(-12);
//        make.width.height.mas_equalTo(30);
//        make.centerY.offset(0);
//    }];
    
    [_deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.width.height.mas_equalTo(30);
        make.centerY.offset(0);
    }];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(30);
        make.centerY.offset(0);
    }];
    
    [_phaseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right);
        make.centerY.offset(0);
        make.right.lessThanOrEqualTo(self.deleteButton.mas_left).offset(-20);
    }];
    
    self.nameLabel.font = SCFont(14);
    self.nameLabel.textColor = [UIColor textTitleColor];
    self.phaseLabel.font = SCFont(12);
    self.phaseLabel.textColor = [UIColor textLightColor];
    
    [self.editButton setImage:[UIImage imageNamed:@"home_icon_edit"] forState:UIControlStateNormal];
    [self.deleteButton setImage:[UIImage imageNamed:@"home_icon_del"] forState:UIControlStateNormal];
}

- (void)setCrop:(WFFarmCrop *)crop {
    if (_crop == crop) {
        return;
    }
    _crop = crop;
    self.nameLabel.text = crop.cropName ?: @"";
    self.phaseLabel.text = [@"/" stringByAppendingString:crop.phaseName ?: @""];
}

@end
